﻿Imports System.Data
Imports System.Data.SqlClient
Public Class DALItensRecurso
    Function localizarTodos(ByVal codigo As Integer) As DataTable
        Dim tab As DataTable
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            cmd.CommandText = "select * from age_itenrecurso where " & _
                "ite_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            tab = objconAgenda.retdadosTab(cmd)
        Catch ex As Exception
            Throw New Exception("", ex)
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function

    Function excluirTodos(ByVal ite_codigo As Integer) As Integer
        Dim ret As Integer
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            cmd.CommandText = "delete from gen_itenrecurso where " & _
                "age_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = ite_codigo

            ret = objconAgenda.executaCmd(cmd)
        Catch ex As Exception
            Throw New Exception("", ex)
        Finally
            cmd = Nothing
        End Try
        Return ret
    End Function
    Function inserir(ByVal itecodigo As Integer, ByVal reccodigo As Integer) As Integer

        Dim cmd As SqlCommand
        Dim Ret As Integer
        Try
            cmd = New SqlCommand
            cmd.CommandText = "insert into gen_itenrecurso(age_codigo, rec_codigo) values (@agecodigo, @reccodigo)"
            cmd.Parameters.Add(New SqlParameter("@agecodigo", SqlDbType.Int)).Value = itecodigo
            cmd.Parameters.Add(New SqlParameter("@reccodigo", SqlDbType.Int)).Value = reccodigo
            Ret = objconAgenda.executaCmd(cmd)
            ' cmd = New SqlCommand
            ' cmd.CommandText = "update gen_recurso set rec_estado='D' where rec_codigo=@reccodigo"
            ' objconAgenda.executaCmd(cmd)
        Catch ex As Exception
            Throw New Exception("Erro. ", ex)
        Finally
            cmd = Nothing
        End Try
        Return Ret
    End Function
End Class
